package com.aaa.product.controller;

import com.aaa.entity.Product;
import com.aaa.product.service.ProductService;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：ludi（206913808@qq.com）
 * @date ：Created in 2022/11/17 16:43
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("product")
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * @create by: ludi（206913808@qq.com）
     * @description: 根据商品id查询产品
     * @create time: 2022/11/17 17:17
     * @param pid
     * @return com.aaa.entity.Product
     */
    @GetMapping("/selectById/{pid}")
    public Product selectById(@PathVariable Long pid) {
        return productService.selectById(pid);
    }

    @GetMapping("/getById/{pid}")
    @SentinelResource("hot") //如果使用热点参数限流 默认对springmvc资源无效。
    public Product getById(@PathVariable Long pid){

        if(pid==1){
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return productService.selectById(pid);
    }


    @Value("${student.name}")
    private String name;

    @GetMapping("getInfo")
    public String getInfo(){
        return "姓名:"+name;
    }


    @GetMapping("write")
    public String write(){
        return "写的业务";
    }

    @GetMapping("read")
    public String read(){
        return "读的业务";
    }
}